package com.ywicc.usblibs.utils;

import java.lang.ref.WeakReference;

/**
 * author : zhouxuan77
 * e-mail : zhouxuan77@163.com
 * time   : 2022/04/07
 * desc   : 静态实现 Runnable，避免发生内存泄漏
 * version: 1.0
 */
public class UsbRunnableUtils {

    public interface UsbRunnableInterface {
        void run();
    }

    public static class UsbRunnable implements Runnable {
        private final WeakReference<UsbRunnableInterface> weakReference;

        public UsbRunnable(UsbRunnableInterface runnableInterface) {
            weakReference = new WeakReference<>(runnableInterface);
        }

        @Override
        public void run() {
            weakReference.get().run();
        }
    }
}